#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<sys/mman.h>
#include<sys/wait.h>


int main(){

    char path[256];
    scanf("%s",path);

    int fd = open(path,O_RDWR);
    if(fd<0){
        perror("open error");
        return -1;
    }
    int len =lseek(fd,0,SEEK_END); // 获取文件的字节数；
    printf("%s 的字节数大小为： %d\n",path,len);

    void *addr = mmap(NULL,len,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
    if(addr==MAP_FAILED){
        perror("mmap error");
        return -1;
    }

    pid_t pid = fork();
    if(pid<0){
        perror("fork error");
        return -1;
    }
    if(pid>0){
        memcpy(addr,"hello pandas",strlen("hello pandas"));
        // 将内存映射字段修改
        wait(NULL);
    }else{
        sleep(3);
        char *p = (char*)addr;
        printf("%s\n",p);
    }

}